// import Mock from 'mockjs';  
// ​ //Mock.mock(url,data)
// Mock.mock("http://abc.com/v5/list",{
// 	name:"zeng101",
// 	age:18
// })

// 引入mockjs
import Mock from "mockjs";
// import { Interface } from "readline";
 
// 获取 mock.Random 对象
const Random = Mock.Random;
interface ItableList {
    id: string
    account: string
    password: string
    address: string
}
// 使用mockjs模拟数据
let tableList:ItableList[] = [
  {
    id: "5ffa80aD-9CF4-0C77-eBFC-f6612BfAcF4F",
    account: "admin",
    password: "123456",
    address: "36918166@qq.com",
  },
  {
    id: "4FcC922C-C72c-95c3-Ef92-FbFAc24cc831",
    account: "ebHoL6",
    password: "i320Hu74fbn2Gi",
    address: "48165263@qq.com",
  },
]
 
// for (let i = 0; i < 20; i++) {
//   let newObject = {
//     id: Random.guid(), // 获取全局唯一标识符
//     account: /^[a-zA-Z0-9]{4,6}$/,
//     password: /^[a-zA-Z]\w{5,17}$/,
//     address: /[1-9]\d{7,10}@qq\.com/,
//   };
//   tableList.push(newObject);
// }
 
/** get请求
 * 获取用户列表
 */
Mock.mock("/api/mockGetList", "get", () => {
  return {
    code: "0",
    data: tableList,
  };
 
});
 

let  data  =  Mock.mock({
    'list|2-5': [{
     'id|+1': 1,
     //生成随机字符串作为名称，string是内置方法
     'name':'@string',
    //生成随机数字
     'point':'@integer',
     //随机日期
     'birthday':'@date'
 }]
})
 
/** post展示表格数据 */
Mock.mock("/api/list", "post", (params) => {
  let newData = JSON.parse(params.body);
  console.log('Random.guid()',newData,Random.guid());
  newData.id = Random.guid();
data.list.push(newData);
  return {
    code: "0",
    message: "success",
    data: data,
  };
});


const chartsData = {
    name: '我是表名Access From111',
    type: 'pie',
    radius: '50%',
    data: [
      { value: 1048, name: 'Search Engine' },
      { value: 735, name: 'Direct' },
      { value: 580, name: 'Email' },
      { value: 484, name: 'Union Ads' },
      { value: 300, name: 'Video Ads' }
    ],
    emphasis: {
      itemStyle: {
        shadowBlur: 10,
        shadowOffsetX: 0,
        shadowColor: 'rgba(0, 0, 0, 0.5)'
      }
    }
  }

  /** get请求
 * 获取图表数据
 */
Mock.mock("/api/getCharts", "post", () => {
    return {
      code: "0",
      data: chartsData,
    };
   
  });

  Mock.mock("/api/login", "post", () => {
    return {
      code: "0",
      data: {sucess:true},
    };
   
  });
// 消息数据
  const msgData = Mock.mock({
    'list|4': [{
     'id|+1': 1,
     //生成随机字符串作为名称，string是内置方法
     'title':'@cword(5,12)',
    //生成随机数字
     'point':'@integer',
     //日期
     'birthday':'一年前'
 }]
})
console.log('mockData',msgData)


// 输出结果
// console.log('mockData', JSON.stringify(data, null, 2))